﻿using Mengsk.ProxyDelivery.Domain;
using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace Mengsk.ProxyDelivery.Print.Domain.PrintDataFormatters
{
    class PrintDataFormatterReceiver_CityOrRegion : PrintDataFormatter
    {
        public override PrintTemplateItemTypes AcceptType
        {
            get { return PrintTemplateItemTypes.RECIVER_CITYORREGION; }
        }


        public override object Format(PrintTemplate template, PrintTemplateItem item, Order order)
        {
            var c = AddressService.ParseCity(order.ReceiverAddress);

            if (c == null)
            {
                MessageBox.Show(order.ReceiverAddress, "没有找到市");
                return "";
            }

            var r = AddressService.ParseRegion(order.ReceiverAddress);

            //没有找到区
            if (r == null)
            {
                return c.Name;
            }

            if (r.Name.Contains("市") || r.Name.Contains("县") || r.Name.Contains("旗") || r.Name.Contains("乡") || r.Name.Contains("镇"))
            {
                return r.Name;
            }

            return c.Name;
        }
    }
}
